package com.qf.utils;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.AnnualCalendar;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * IntelliJ IDEA -> quartz
 * 2019/11/29 19:23
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
public class QuartzUtils {
     public void zhixing(){
         try {
             JobDetail jobdetail = new JobDetail("jobdetail", UserJob.class);
             JobDataMap jobDataMap = new JobDataMap();//用来保存任务过程中的数据
             jobDataMap.put("username","李四");
//             SimpleTrigger trigger = new SimpleTrigger("trigger", 5, 2000);
//             CronTrigger cronTrigger = new CronTrigger("trigger", "mygroup", "* 57 15 29 11 ?");
             CronTrigger cronTrigger = new CronTrigger("trigger", "mygroup", "* * * * * ?");
             //进行排除时间的   操作
          //创建排除时间的工具类
             AnnualCalendar annualCalendaer = new AnnualCalendar();
          //创建日期对象
             Calendar instance = GregorianCalendar.getInstance();
             instance.set(Calendar.MONTH,10);
             instance.set(Calendar.DAY_OF_MONTH,30);
             annualCalendaer.setDayExcluded(instance,true);
             //调度器
             StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
             Scheduler scheduler = stdSchedulerFactory.getScheduler();
             scheduler.addCalendar("abc",annualCalendaer,true,true);
             cronTrigger.setCalendarName("abc");
            scheduler.scheduleJob(jobdetail, cronTrigger);
            scheduler.start();
         } catch (SchedulerException e) {
             e.printStackTrace();
         } catch (ParseException e) {
             e.printStackTrace();
         }
     }

    public static void main(String[] args) {
        QuartzUtils quartzUtils = new QuartzUtils();
        quartzUtils.zhixing();
    }
}
